import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import magick.ImageInfo;
import magick.MagickException;
import magick.MagickImage;


public class Test {
	public static void main(String[] args) throws IOException, MagickException {
//		BufferedImage img = ImageIO.read(new File(""));   
//        int h = img.getHeight();   
//        int w = img.getWidth();   
//           
//        if(h>=96 && w >=96){   
//            int nw = 96;   
//            int nh = (nw * h) / w;   
//            if(nh>96) {   
//                nh = 96;   
//                nw = (nh * w) / h;   
//            }   
//            ByteArrayOutputStream out = new ByteArrayOutputStream();   
//            BufferedImage dest = new BufferedImage(nw, nh,BufferedImage.TYPE_4BYTE_ABGR);   
//            dest.getGraphics().drawImage(img,0,0,nw, nh,null);   
//
//            //Gif89Encoder.encode(dest, out);   
//            //ImageIO.write(dest, "gif", out);   
//           // imageThumbnail = out.toByteArray();   
//        }   
//        else{   
//           // imageThumbnail = imageData;   
//        } 
		
		
		new Test().test();
	}
	
	public void test() throws MagickException {
		System.setProperty("jmagick.systemclassloader", "no");// ���ûʲô��˵�ģ��հ������ 

		//����·��������
		String sfilepath = "E:/project/iyoulin/T0762528104545.jpg";
  	    String sfilepath2 = "E:/project/iyoulin/03����/web/userpic/grouppic/group0/T0762528104545_.jpg";
  	  
		ImageInfo info = new ImageInfo( sfilepath); 
		MagickImage image = new MagickImage(info); 
		// Dimension dim = fromImage.getDimension(); 
		// double w = dim.getWidth(); 
		// double h = dim.getHeight(); 
		// int toHeight = (int) (h * 110 / w);// ����ȱ������ 
		// 
		int width = 100;
		int height = 50;
		 MagickImage toImage = image.scaleImage(width, height);// ��Ų��� 
		 toImage.setFileName(sfilepath2);// ���������ļ��� 
		 toImage.writeImage(info); // ���� 

		// ����һ�� 
		/* 
		* info.setPage("50x50+0+0"); 
		* info.setUnits(ResolutionType.PixelsPerInchResolution); 
		* info.setColorspace(ColorspaceType.RGBColorspace); 
		* info.setBorderColor(PixelPacket.queryColorDatabase("red")); 
		* MagickImage image = new MagickImage(info); 
		* image.setImageAttribute("Comment", "Processed by JMagick"); 
		* System.out.println("Quality is "+image.getQuality()); 
		* System.out.println("Colorspace is " + image.getColorspace()); 
		* System.out.println("Resolution units is " + image.getUnits()); 
		* System.out.println("X resolution is " + image.getXResolution()); 
		* System.out.println("Y resolution is " + image.getYResolution()); 
		* System.out.println("Size blob is " + image.sizeBlob()); 
		* System.out.println("Colors " + image.getColors()); 
		* System.out.println("Total colors " + image.getTotalColors()); 
		* System.out.println("Depth is "+image.getDepth()); 
		* image.signatureImage(); image.setFileName("D:/image/dcopy.jpg"); 
		* image.writeImage(info); 
		*/ 

		// �ı䱳��ɫ 
		/* 
		* System.out.println("Old colour " + image.getBackgroundColor()); 
		* image.setBackgroundColor(PixelPacket.queryColorDatabase("red")); 
		* System.out.println("New colour " + image.getBackgroundColor()); 
		* image.setBorderColor(PixelPacket.queryColorDatabase("green")); 
		* MagickImage borderedImage = image.borderImage(new Rectangle(0, 0, 10, 
		* 20)); borderedImage.setFileName("D:/image/border.jpg"); 
		* borderedImage.writeImage(info); 
		*/ 

		//image = new MagickImage(new ImageInfo("D:/image/pics.jpg")); 
		// MagickImage rotated = image.rotateImage(90.0);// ��ת 
		// rotated.setFileName("D:/image/rotated.jpg"); 
		// rotated.writeImage(info); 
		// MagickImage sheared = image.shearImage(50.0, 10.0);// ��� 
		// sheared.setFileName("D:/image/sheared.jpg"); 
		// sheared.writeImage(info); 
		// MagickImage scaled = image.scaleImage(100, 80); 
		// scaled.setFileName("D:/image/scaled.jpg"); // �޼� 
		// scaled.writeImage(info); 

		/*********************************************************************** 
		* blurImage�������� 
		* charcoalImage���ľ̿ͼ 
		* edgeImage  ���� 
		* embossImage ���� 
		* flipImage ��ֱ��ת 
		* flopImage ˮƽ��ת 
		* gaussianBlurImage ���� 
		* implodeImage �������� 
		* magnifyImage �Ŵ� 
		* medianFilterImage �˲� 
		* minifyImage ��С 
		* rotateImage(90.0);// ��ת 
		* shearImage(50.0, 10.0);// ��� 
		* image.scaleImage(100, 80); �޼� 
		* montageImages(new MontageInfo(new ImageInfo())); ΪͼƬ���ϱ߿� 
		* oilPaintImage �������� 
		* reduceNoiseImage ������������ 
		* rollImage �ڶ� 
		* sampleImage �����͸� 
		* scaleImage  �����͸� 
		* spreadImage ͼƬ��ɢ 
		* swirlImage ���� 
		* unsharpMaskImage ����ģͼ�� 
		* waveImage Ϊͼ�����ë�� 
		* zoomImage �佹 
		*/ 


//		MagickImage aa = image.addNoiseImage(5); 
//		aa.setFileName("d:/image/aa.jpg"); 
//		aa.writeImage(info); 

		// ͹���, ����� 
		/* 
		* MagickImage raisedImage = new MagickImage(info); 
		* raisedImage.raiseImage(new Rectangle(0, 0, 10, 20), true); 
		* raisedImage.setFileName("D:/image/raised.jpg"); 
		* raisedImage.writeImage(info); 
		*/ 

		// ͼƬ������� 
		/* 
		* System.out.println("Number of generic profiles " + 
		* image.getGenericProfileCount()); 
		* displayProfile(image.getColorProfile()); image.setColorProfile(new 
		* ProfileInfo()); displayProfile(image.getColorProfile()); 
		* image.setColorProfile(new ProfileInfo("Test", new byte[20])); 
		* displayProfile(image.getColorProfile()); MagickImage images[] = new 
		* MagickImage[2]; images[0] = image; images[1] = image; MagickImage 
		* seqImage = new MagickImage(images); MontageInfo montageInfo = new 
		* MontageInfo(new ImageInfo()); 
		* montageInfo.setFileName("D:/image/montage.jpg"); 
		* montageInfo.setTitle("Melbourne"); montageInfo.setBorderWidth(5); 
		* MagickImage montage = seqImage.montageImages(montageInfo); 
		* montage.writeImage(new ImageInfo()); 
		*  // Converting the montage into a blob montage.setMagick("JPG"); 
		* byte[] mblob = montage.imageToBlob(new ImageInfo()); 
		* System.out.println("Length " + mblob.length); 
		*  // ��� MagickImage average = seqImage.averageImages(); 
		* average.setFileName("D:/image/average.jpg"); average.writeImage(new 
		* ImageInfo()); 
		*  // ȥ�ߵ� info = new ImageInfo(); byte[] blob = 
		* image.imageToBlob(info); 
		*  // Blob to image info = new ImageInfo(); MagickImage blobImage = new 
		* MagickImage(info, blob); Dimension imageDim = 
		* blobImage.getDimension(); System.out.println("Blob width is " + 
		* imageDim.width); System.out.println("Blob heght is " + 
		* imageDim.height); System.out.println(imageDim); 
		* blobImage.setFileName("D:/image/blob.jpg"); 
		* blobImage.writeImage(info); 
		*  // ��jpg���gif image.setMagick("GIF"); blob = image.imageToBlob(info); 
		* try { FileOutputStream out = new 
		* FileOutputStream("D:/image/blob.gif"); out.write(blob); out.close(); } 
		* catch (IOException ex) { System.out.println("Unable to write blob to 
		* file: " + ex); } 
		* 
		*  // ��ϵ�� imageDim = image.getDimension(); System.out.println("Width is " + 
		* imageDim.width); System.out.println("Height is " + imageDim.height); 
		* System.out.println("Depth is " + image.getDepth()); 
		* System.out.println("Storage class is " + image.getStorageClass()); 
		* System.out.println("Comment is \"" + 
		* image.getImageAttribute("Comment") + "\""); MagickImage clonedImage = 
		* image.cloneImage(0, 0, false); 
		* clonedImage.setFileName("D:/image/clone.jpg"); 
		* clonedImage.writeImage(info); 
		*/ 

		// ��..��� 
		/* 
		* MagickImage quantizedImage = new MagickImage(new ImageInfo( 
		* "D:/image/pics.jpg")); QuantizeInfo quantizeInfo = new 
		* QuantizeInfo(); 
		* quantizeInfo.setColorspace(ColorspaceType.GRAYColorspace); 
		* quantizeInfo.setNumberColors(256); quantizeInfo.setTreeDepth(4); 
		* System.out.println("QuantizeImage " + 
		* quantizedImage.quantizeImage(quantizeInfo)); 
		* System.out.println("Colors " + quantizedImage.getColors()); 
		* System.out.println("Total colors " + 
		* quantizedImage.getTotalColors()); 
		* quantizedImage.setFileName("D:/image/quantized.png"); 
		* quantizedImage.writeImage(info); 
		*/ 

		// ����ͼƬ..���ļ�д��ͼƬ���� 
		/* 
		* MagickImage blankImage = new MagickImage(); byte[] pixels = new 
		* byte[200 * 100 * 4]; for (int i = 0; i < 200 * 100; i++) { pixels[4 * 
		* i] = (byte) 255; pixels[4 * i + 1] = (byte) 255; pixels[4 * i + 2] = 
		* (byte) 255; pixels[4 * i + 3] = (byte) 0; } 
		* blankImage.constituteImage(200, 100, "RGBA", pixels); 
		*  // Put a red rectangle around the border DrawInfo drawInfo = new 
		* DrawInfo(new ImageInfo()); drawInfo.setPrimitive("Rectangle 10 10 190 
		* 90"); drawInfo.setStroke(PixelPacket.queryColorDatabase("red")); 
		* drawInfo.setFill(PixelPacket.queryColorDatabase("white")); 
		* blankImage.drawImage(drawInfo); 
		*  // Annotate the image with a green Hello ImageInfo blankImageInfo = 
		* new ImageInfo(); DrawInfo annotateInfo = new 
		* DrawInfo(blankImageInfo); annotateInfo.setOpacity(0); 
		* annotateInfo.setFont("fixed"); 
		* annotateInfo.setFill(PixelPacket.queryColorDatabase("green")); 
		* annotateInfo.setText("Wangxiaochen"); 
		* annotateInfo.setGeometry("+30+30"); 
		* blankImage.annotateImage(annotateInfo); 
		* 
		* blankImage.setFileName("D:/image/blank.jpg"); 
		* blankImage.writeImage(info); 
		* 
		* 
		* //͸�� blankImage.transparentImage( 
		* PixelPacket.queryColorDatabase("white"), 65535); 
		* blankImage.setFileName("D:/image/transparent.png"); 
		* blankImage.writeImage(info); 
		*  // ��� Rectangle rect = new Rectangle(0, 0, 80, 40); rect = new 
		* Rectangle(20, 20, 150, 120); MagickImage cropped = 
		* image.cropImage(rect); cropped.setFileName("D:/image/cropped.jpg"); 
		* cropped.writeImage(info); 
		* 
		* //ĥ�� MagickImage sharpened = image.sharpenImage(1.0, 5.0); 
		* sharpened.setFileName("D:/image/sharpened.jpg"); 
		* sharpened.writeImage(info); 
		*  // Despeckle image MagickImage despeckled = image.despeckleImage(); 
		* despeckled.setFileName("D:/image/despeckled.jpg"); 
		* despeckled.writeImage(info); 
		* 
		*  // Convolve image double[] kernel = new double[9]; for (int i = 0; i < 
		* 9; i++) { kernel[i] = 1.0; } kernel[4] = 2.0; MagickImage 
		* convolvedImage = image.convolveImage(3, kernel); 
		* convolvedImage.setFileName("D:/image/convolved.jpg"); 
		* convolvedImage.writeImage(info); 
		*  // Finally display the image. // MagickWindow window = new 
		* MagickWindow(image); // window.setVisible(true); 
		*  // MagickInfo test MagickInfo minfo = new MagickInfo("JPEG"); 
		* System.out.println("JPG description: " + minfo.getDescription()); 
		*/ 

	}
}
